﻿using Domain;
using Domain.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Web.Filters;

namespace Web
{
    /// <summary>
    /// 基础控制器   
    /// </summary>       
    public class BasicController : Controller
    {
        /// <summary>
        /// 登录的客户信息
        /// </summary>      
        private User loginUser;

        /// <summary>
        /// 获取数据库上下文对象
        /// </summary>
        public RepositoryContext DbContext { get; private set; }

        /// <summary>
        /// 基础控制器
        /// </summary>
        public BasicController()
        {
            this.DbContext = new RepositoryContext();
        }

        /// <summary>
        /// 设置登录信息到私到字段中
        /// </summary>
        /// <param name="value"></param>
        public void SetLoginUser(User value)
        {
            this.loginUser = value;
        }

        /// <summary>
        /// 设置或设置登录的客户信息
        /// [session]操作
        /// </summary>
        public User LoginUser
        {
            get { return this.loginUser ?? (this.loginUser = this.Session["LoginUser"] as User); }
            set
            {
                this.loginUser = value;
                this.Session["LoginUser"] = value;
            }
        }
     
        protected override void Dispose(bool disposing)
        {
            this.DbContext.Dispose();
            base.Dispose(disposing);
        }
    }
}